package edu.washington.ling.syntric.util;

import java.util.*;

public class Utils {
	public static String join(Collection<String> s, String delimiter) {
	    if (s == null || s.isEmpty()) return "";
	    Iterator<String> iter = s.iterator();
	    StringBuilder builder = new StringBuilder(iter.next());
	    while( iter.hasNext() )
	    {
	        builder.append(delimiter).append(iter.next());
	    }
	    return builder.toString();
	}
	public static String join(String[] s, String delimiter) {
	    if (s == null) return "";
	    String joined = "";
	    for (int i = 0; i < s.length; i++)
	    {
	        if (i < s.length - 1) {
	        	joined += s[i] + delimiter;
	        }
	        else {
	        	joined += s[i];
	        }
	    }
	    return joined;
	}
	public static void reverse(Object[] data) {
	    int left = 0;
	    int right = data.length - 1;

	    while( left < right ) {
	        // swap the values at the left and right indices
	        Object temp = data[left];
	        data[left] = data[right];
	        data[right] = temp;

	        // move the left and right index pointers in toward the center
	        left++;
	        right--;
	    }
	}
}
